﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace GestorDeFlotasDesktop.Validator
{
    public abstract class AbstractValidator
    {
        private string errorMsg;
        private bool isValid;
        private string regexpresion;
        private string propertiesRegex;

        public abstract bool Validate (string cadena);
        
        public string ErrorMsg 
        {
            get { return errorMsg; }
            set { errorMsg = value; } 
        }
        public bool IsValid 
        {
            get { return isValid; }
            set { isValid = value; }
        }
        public string Regexpresion 
        {
            get {
                if (regexpresion == null || "".Equals(regexpresion))
                {
                    regexpresion = GetProperties(propertiesRegex);
                }
                return regexpresion; }
            set { regexpresion = value; }
        }
        public string PropertiesRegex
        {
            get { return propertiesRegex; }
            set { propertiesRegex = value; }
        }

        private string GetProperties(string nameProperties) 
        {
            IEnumerator enumerator = Properties.Settings.Default.Properties.GetEnumerator();
            while (enumerator.MoveNext())
            {
                if (nameProperties.Equals(((System.Configuration.SettingsProperty)enumerator.Current).Name))
                {
                    return "" + ((System.Configuration.SettingsProperty)enumerator.Current).DefaultValue;
                }
            }
            throw new Expeciones.AppException("Error al recuperar la properties");
        }
    }
}
